home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Beginer C please help me
- Date: 22 Mar 1996 12:12:45 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4iun2d$896@umbc9.umbc.edu>
- References: <DoLCFx.B7x.0.bloor@torfree.net>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Sherif Asif <bz786@torfree.net> wrote:
- |> This may be a stupid mistake but "please help" me.
- |> Thank you very much.
- |>
- |> #include <stdio.h>
- |> #include <math.h>
- |> main ()
- |> {
- |> float n;
- |> n=(9/5);
-
- The calculation 9/5 is an integral calculation. Since 5 only goes into
- 9 one time (with a remainder that gets discarded) your answer is 1.
- Perhaps you have mistakenly assumed that since the result is being assigned
- to a float that something magical would happen? The only way to get the
- correct answer is to perform the calculation in floating point. Either
- a cast or using explicit floating point constants will do the trick.
-
- |> printf ("n= %1.3f\n", n);
-
- You may want a 'return (0);' here as well.
-
- |> }
- |> I have complied and run the programme & I got the answer n=1.000
- |> but Iam supposed to get answer 1.8.
- |> Why I got this answer?
-
- Make the 9/5 to 9.0/5.0.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-